#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<ctype.h>

int ispalindromo(char *string);
int tamArquivo(FILE *f);

int main(){

	int cont = 0;
	int stop = 0;
	int isword;
	int i = 0;
	double time;
	clock_t start; 
	clock_t end;

	FILE *arq;

	arq = fopen("wikipedia.txt","r");

	if(arq == NULL)
		printf("Falha ao abrir o arquivo");
	else{
		char *word;
		
		word = malloc(10*sizeof(char));
		start = clock();
		while(stop == 0){
			fscanf (arq, "%s", word);
			if(!feof(arq)){
				if(strlen(word) == 6){
					isword = 1;
					for(i = 0 ; (i < strlen(word)) && isword ; i++ ){
						if(!isalnum(word[i]))
							isword = 0;
					}
					if(ispalindromo(word) && isword ){				
						cont++;
						printf("%s\n",word);
					}

				}
			}else
				stop = 1;
		}
		end = clock();
	}
	printf("%d\n",cont);
	time = ((double)(end-start)/(double)CLOCKS_PER_SEC);
	printf("tempo é %lf\n", time);
	return 0;
}

int ispalindromo(char *string){

	
	int i=0;
	int tam = strlen(string);
	
	if( tam%2 == 0 ){

		for(i = 0 ; i < tam/2 ; i++){
			if(string[i] != string[tam-1-i])
				return 0;

		}
		return 1;
	}
	else{
		while( i != tam/2){
			if(string[i] != string[tam-1-i])
				return 0;
			i++;
		}
	
		return 1;
	}
}
int tamArquivo(FILE *f){
	
	int size = 0;
	fseek(f,0,SEEK_END);
	size = ftell(f);
	fseek(f,0,SEEK_SET);
	return size;

}


